package com.cgx.order.service;

import com.cgx.feign.clients.UserClient;
import com.cgx.feign.pojo.User;
import com.cgx.order.mapper.OrderMapper;
import com.cgx.order.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private UserClient userClient;
//    @Autowired
//    private RestTemplate restTemplate;
//
//    public Order queryOrderById(Long orderId) {
//        // 1.查询订单
//        Order order = orderMapper.findById(orderId);
//        // 2.创建url请求
//        String url = "http://userservice/user/"+order.getUserId();
//        User user = restTemplate.getForObject(url, User.class);
//        order.setUser(user);
//        // 4.返回
//        return order;
//    }
    public Order queryOrderById(Long orderId){
        Order order = orderMapper.findById(orderId);
        //利用feign远程调用
        User user = userClient.findById(order.getUserId());
        order.setUser(user);
        return order;
    }

}
